package algorithm;

import datastructure.Fraction;
import datastructure.Pair;
import java.util.ArrayList;
import java.util.HashMap;

public class NaiveBayesModel {
  
  private ArrayList<HashMap<String,Pair<Fraction,Fraction>>> data;
  private Pair<Fraction,Fraction> probability;
  
  public NaiveBayesModel (ArrayList<HashMap<String,Pair<Fraction,Fraction>>> data, Pair<Fraction,Fraction> probability) {
    this.data = data;
    this.probability =  probability;
    
  }
  
  public String executeInstance (ArrayList<String> instance) {
    double right = probability.first.getDouble() , wrong = probability.second.getDouble();
    for (int attribute_number = 0; attribute_number < instance.size(); attribute_number++) {
      right *= data.get(attribute_number).get(instance.get(attribute_number)).first.getDouble();
      wrong *= data.get(attribute_number).get(instance.get(attribute_number)).second.getDouble();
    }
    return (right >= wrong) ? "1":"0";
  }
  
}
